package com.demo.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@SuppressWarnings("unused")
//@Component("userBean")
//@Lazy
public class User implements InitializingBean, DisposableBean, ApplicationContextAware {
    private String name;
    private String gender;

    private ApplicationContext context;

    public User() {
        System.out.println("构造方法初始化");
        this.gender = "男";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("User: destroy...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("男".equals(this.gender));
        System.out.println("afterPropertiesSet回调");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("applicationContext注入");
        this.context = applicationContext;
        Customer customer = (Customer) this.context.getBean("customerBean");
        System.out.println(customer);
    }
}
